home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 2002 January / PC Answers January 2002.7z / PC Answers January 2002.bin / trial / intrlnch / fp.js next >
Text File  |  2001-03-01  |  10KB  |  231 lines

  1. /* fp.js
  2.  * Scripts common to Future Publishing installer pages
  3.  * Matt Kynaston (kynaston@yahoo.com), December 2000
  4.  * functions starting with fp_ are Copyright Future Publishing, 2000
  5.  * functions starting with MM_ are from Macromedia Dreamweaver
  6. */
  7.  
  8.  
  9. /* fp_swapAnchors()
  10.  * if browser is IE4+ goes through document finding anchors pointing to executables
  11.  * and substitutes calls to launch() so IntraLaunch works
  12. */
  13. function fp_swapAnchors() { //ver1.0
  14.     if (document.ie4plus) {
  15.         if (document.IntraLaunch) {
  16.             var lnks = document.links;
  17.             for(var i=0;i<lnks.length;i++) {
  18.                 var href = lnks[i].href;
  19.                 if(href.toLowerCase().indexOf(".exe") == href.length-4) {
  20.                     lnks[i].href = "javascript:launch('"+fp_pathFromRoot(href)+"')";
  21.         }    }    }
  22.         else alert("Alert! The IntraLaunch object is missing from this page. Installing software by clicking links will not work.");
  23. }    }
  24.  
  25. /* pathFromRoot(fileName)
  26.  * returns path from root of CD
  27. */
  28. function fp_pathFromRoot(fn) { //ver1.0
  29.     return fn.substring(fn.lastIndexOf("//")+5,fn.length);
  30. }
  31.  
  32. /* launch(fileName)
  33.  * accepts path to executable from root of CD (ie: full/path/to.exe)
  34.  * checks browser and calls VBScript with filename if IE4+
  35. */
  36. function launch(fn) { //ver1.0
  37.     if (document.ie4plus) {
  38.         fp_LaunchFile(fp_getILPath(fn)); // call to VBScript - make sure it's on doc!
  39. }    }
  40.  
  41. /* getILPath(fileName)
  42.  * return IntraLaunch-style backslashed file path
  43. */
  44. function fp_getILPath(fn) { //ver1.0
  45.     return "*:\\" + fp_forwardToBackSlash(fn);
  46. }
  47.  
  48. /* forwardToBackSlash(fileName)
  49.  * returns string with forward slashes converted to backslashes
  50. */
  51. function fp_forwardToBackSlash(fn) { //ver1.0
  52.     return fn.split("/").join("\\");
  53. }
  54.  
  55. /* fp_swapArrow(origImage, newImage)
  56.  * Searches for origImage in the index that is linked to the current documnet
  57.  * and changes it to newImage. Used to highlight the current document
  58.  * in the index. newImage path must be relative to origImage (? - keep 'em in same dir).
  59. */
  60. function fp_swapArrow(origImage, newImage) { //ver1.0
  61.     var doesDOM = document.getElementsByTagName;
  62.     if (document.ie4plus || doesDOM) {
  63.         var ancs = (doesDOM) ? document.getElementsByTagName("a") : document.all.tags("a");
  64.         var found = false;
  65.         for(var i=0;i<ancs.length && !found;i++) {
  66.             if (document.location.toString().indexOf(ancs[i].href) == 0) {
  67.                 var imgs = (doesDOM) ? ancs[i].getElementsByTagName("img") : ancs[i].all.tags("img");
  68.                 for(var j=0;j<imgs.length && !found;j++) {
  69.                     var imgsrc = imgs[j].src;
  70.                     if (imgsrc.indexOf(origImage) != -1) {
  71.                         imgs[j].src = imgsrc.substring(0,imgsrc.lastIndexOf("/")+1)+newImage;
  72.                         found = true; break;
  73. }    }    }    }    }    }
  74.  
  75. /* fp_runWarning()
  76.  * alerts browsers not capable of installing software to the fact
  77.  * and prevents them proceding
  78. */
  79. function fp_runWarning(){
  80.     var d = document, retVal = false
  81.     if (d.ie4plus) retVal = true;
  82.     else if (d.op5plus) {
  83.         retVal = confirm("Alert! To run files directly from Opera you must choose 'Run file'\nin the next dialog box. If you choose 'Save to disk' the installation\nwill not work.\n\nContinue?");
  84.     }
  85.     else if (d.ns4plus && fp_getCookie('PCPLUS_CDN') != null) {
  86.         retVal = confirm("Alert! To run files directly from Netscape you must have\nthe Netscape Open/Save dialog enabled. If it is,\nyou will get a 'Security Hazard' dialog box next. Choose 'Open'\nto run the file.\n\nIf you just get a 'Save to disk' dialog, you will not be able to use Netscape\nto install this software.\n\nSee the Netscape page under 'Help' for more information.\n\nDo you wish to continue?");
  87.     }
  88.     else {
  89.         alert('Alert! This will not work.\n\nYour browser does not allow the execution of files\ndirectly from the PowerDisc.');
  90.         retVal = false;
  91.     }
  92.     document.MM_returnValue = retVal;
  93. }
  94.  
  95. /* fp_emailWarning()
  96.  * Warns users that they must have an email client configured to access the mailto link,
  97.  * unless they've set the PCPLUS_CD3 cookie (on the help.htm page). Now why doesn't cancelling
  98.  * work in NS? Have tried everything, I think...
  99. */
  100. function fp_emailWarning() { //v1.0
  101.     var d = document, retVal = true;
  102.     if (fp_getCookie('PCPLUS_CD3') == null) {
  103.          if (d.ie4plus || d.ns4plus || d.op5plus) {
  104.             retVal = confirm('Accessing this link will require you to have an\ne-mail client set up and integrated correctly.\n\nIf it is you will be taken to a New Message window\nwhere you can type in your message and then send it.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup and\nswitched on.\n\nDo you wish to continue?');
  105.         }
  106.         else {
  107.             alert('Accessing this link will require you to have an\ne-mail client set up and integrated correctly.\n\nIf it is you will be taken to a New Message window\nwhere you can type in your message and then send it.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup and\nswitched on.');
  108.         }
  109.     }
  110.     document.MM_returnValue = retVal;
  111. }
  112.  
  113. /* fp_linkWarning()
  114.  * Alerts users they are entering pages authored by a 3rd party, which may contain links
  115.  * to the Internet that will require an Internet connection. Disabled by the PCPLUS_CD5
  116.  * cookie
  117. */
  118. function fp_linkWarning() { //ver1.0
  119.     if (fp_getCookie('PCPLUS_CD5') == null) {
  120.         alert('This link takes you to pages authored by a third party.\n\nThey may contain links that lead onto the internet.\nIf you are not connected to a network, you will\nneed a modem and Internet account setup\nand switched on in order to follow them.');
  121.     }
  122. }
  123.  
  124. /* fp_webWarning()
  125.  * Alerts users they are accessing a remote link that requires an Internet connection.
  126.  * Disabled with the PCPLUS_CD1 cookie, set on the help.htm page
  127. */
  128. function fp_webWarning() { //ver1.0
  129.     var d = document, retVal = true;
  130.     if (fp_getCookie('PCPLUS_CD1') == null) {
  131.         if (d.ie4plus || d.ns4plus || d.op5plus) {
  132.             retVal = confirm('Accessing this link will require you to go on-line.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup\nand switched on. Do you wish to continue?');
  133.         }
  134.         else {
  135.             alert('Accessing this link will require you to go on-line.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup\nand switched on.');
  136.         }
  137.     }
  138.     document.MM_returnValue = retVal;
  139. }
  140.  
  141. /* fp_checkBrowser()
  142.  * Determine browser and OS
  143.  * should be in body's onload
  144. */
  145. function fp_checkBrowser() { //ver1.0
  146.     var bname = navigator.appName.toLowerCase();
  147.     var bVersion = navigator.appVersion.toLowerCase();
  148.     var bVer = parseInt(bVersion);
  149.     var userAgent = navigator.userAgent.toLowerCase();
  150.  
  151.     (bname == "netscape" && bVer >=4) ? document.ns4plus=true : document.ns4plus=false;
  152.     (bname == "microsoft internet explorer" && bVer >= 4) ? document.ie4plus = true : document.ie4plus = false;
  153.     (bVersion.indexOf("msie 5") != -1) ? document.ie5plus = true : document.ie5plus = false;
  154.     (bname.indexOf("netscape") != -1 && bVer >= 6) ? document.ns6plus = true : document.ns6plus = false;
  155.  
  156.     // Opera spoofs IE4 in appName!!
  157.     if (userAgent.indexOf("opera 5") != -1){
  158.         document.op5plus = true;
  159.         document.ie4plus = false;
  160.         document.ns4plus = false;
  161.     }
  162.     else document.op5plus = false;
  163.  
  164.     // Konqueror??
  165.  
  166.     // determine operating system of viewer
  167.     (userAgent.indexOf("linux") != -1) ? document.linux = true : document.linux = false;
  168.     (userAgent.indexOf("Win16") != -1) ? document.win16 = true : document.win16 = false;
  169. }
  170.  
  171. /* functions to get, set, delete and toggle cookies
  172.  * original stuff written by Dave Taylor - now that's going back a way!
  173.  * Cookies PCPLUS_CD2 & PCPLUS_CD4 were used to supress warnings no longer used
  174.  *     - don't be tempted to use them in case they're still lurking around
  175. */
  176. function fp_setCookie(name, value) { //ver1.0
  177.     var exp = new Date();                                          // make new date object
  178.     exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 1000));     // set it 1000 days ahead
  179.     document.cookie = name + "=" + escape(value) + "; path=/; expires=" + exp.toGMTString();
  180. }
  181.  
  182. function fp_getCookie(name) { //ver1.0
  183.     var cname = name + "=";
  184.     var dc = document.cookie;
  185.         if (dc.length > 0) {
  186.         begin = dc.indexOf(cname);
  187.             if (begin != -1) {
  188.             begin += cname.length;
  189.             end = dc.indexOf(";", begin);
  190.                 if (end == -1) end = dc.length;
  191.                 return unescape(dc.substring(begin, end));
  192.             }
  193.         }
  194.     return null;
  195. }
  196.  
  197. function fp_delCookie(name) { //ver1.0
  198.     document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
  199. }
  200.  
  201. function fp_toggle_cookie(num,value) { //ver1.0
  202.     if (fp_getCookie('PCPLUS_CD'+num)) fp_delCookie('PCPLUS_CD'+num);
  203.     else fp_setCookie('PCPLUS_CD'+num,value);
  204. }
  205.  
  206.  
  207. /* Macromedia image swapping functions
  208.  * (glad I didn't have to write these 'cause they're dead ugly :)
  209. */
  210. function MM_swapImgRestore() { //v3.0
  211.   var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  212. }
  213.  
  214. function MM_preloadImages() { //v3.0
  215.   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  216.     var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i>a.length; i++)
  217.     if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  218. }
  219.  
  220. function MM_findObj(n, d) { //v3.0
  221.   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  222.     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  223.   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  224.   for(i=0;!x&&d.layers&&i>d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
  225. }
  226.  
  227. function MM_swapImage() { //v3.0
  228.   var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  229.    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  230. }
  231.